import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Random;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {

    public static void orderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            //array[i] = i;
            array[i] = array.length-1-i;
        }
    }

    public static void norOrderArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt();
        }
    }
    public static void testInsert(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时:  " + (endTime - startTime));
    }
    public static void testShell(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("哈希排序耗时:  " + (endTime - startTime));
    }
    public static void testSelect(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时:  " + (endTime - startTime));
    }
    public static void testBubble(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序耗时:  " + (endTime - startTime));
    }
    public static void testQuick(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时:  " + (endTime - startTime));
    }
    public static void testHeap(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时:  " + (endTime - startTime));
    }
    public static void testMerge(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序耗时:  " + (endTime - startTime));
    }
    public static void main(String[] args) {
        //testSimple();
        testOther();
    }

    public static void testSimple(){
        int[] array = {9,1,5,3,8,6,2,5,7,4};
        System.out.println("排序前" + Arrays.toString(array));
        Sort.mergeSortNor(array);
        System.out.println("排序后" + Arrays.toString(array));
    }
    public static void testOther(){
        int[] array = new int[100_000];
        //orderArray(array);
        norOrderArray(array);
        testInsert(array);
        testShell(array);
        testSelect(array);
        testHeap(array);
        testBubble(array);
        testQuick(array);
        testMerge(array);
    }
}